//
//  HomeRecommendHightQualityCategoryView.swift
//  HomeRecommendHightQualityCategoryView
//
//  Created by Ben on 2021/8/19.
//

import SwiftUI

struct HomeRecommendHightQualityCategoryView: View {
    var categoryIconName: String
    var categoryTitle: String
    var categoryDoc: String
    
    @State private var categoryIconHeight: CGFloat = 0
    var body: some View {
        VStack {
            
            GeometryReader { proxy -> AnyView in
                
                let width = proxy.frame(in: .global).width
                
                
                return AnyView(
                    ZStack {
                        
                        RoundedRectangle(cornerRadius: width * 0.5)
                            .fill(.white)
                            .frame(width: width - 10, height: width - 10)
                        
                        Image(categoryIconName)
                            .resizable()
                            .aspectRatio(contentMode: .fit)
                            .frame(width: width - 35, height: width - 35)
                    }
                        .onAppear(perform: {
                            categoryIconHeight = width
                        })
                    
                )
            }
            .frame(height: categoryIconHeight)
            
            Text(categoryTitle)
                .font(.system(size: 16, weight: .semibold))
                .offset(y: -5)
            Text(categoryDoc)
                .font(.system(size: 12, weight: .medium))
                .foregroundColor(Color.black.opacity(0.5))

        }
        .frame(maxWidth: .infinity)
        
    }
}
